<#assign contextRoot = "/arcapp" />

<#function isMobile>	
	<#if m_site.m_dev["category"]?lower_case == "smartphone">
		<#return true>
	</#if>
    <#return false>
</#function>

<#function isTablet>
	<#if m_site.m_dev["category"]?lower_case == "tablet">
		<#return true>
	</#if>
    <#return false>
</#function>

<#function isDesktop>
	<#if m_site.m_dev["category"]?lower_case == "personal_computer">
		<#return true>
	</#if>
    <#return false>
</#function>

<#macro scripts>
  <script type="text/javascript">
    ${scriptsObj!""}
  </script>
</#macro>

<#function getList input>
  <#if !input?is_enumerable>
    <#return [input]>
  <#else>
    <#return input>
  </#if>
</#function>

<#--
Returns string according set size with ellipsis at the end - blogs utility.
@return {String}
-->
<#function stringToDisplay totalChar currentString>
    <#assign tempString = "">
    <#assign currentChar = "">
    <#list totalChar..currentString?length as i>
        <#if (i+1) <= currentString?length>
            <#assign currentChar = currentString?substring(i, i+1)>
            <#if (currentChar != " ") >
                <#assign tempString =  tempString + currentChar>
            <#else>
                <#break>
            </#if>
        <#else>
          <#assign tempString =  tempString + currentChar>
        </#if>
    </#list>
    <#assign stringToRender = currentString?substring(0, totalChar) + tempString>
    <#return stringToRender + "..." />
</#function>

<#function ellipsis text  num>
	<#if text?length gt num>
		<#return stringToDisplay(num, text) />
	</#if>
	<#return text />
</#function>

<#macro navFilter moduleTitle count>
	<div class="page-header">
			<h1>${moduleTitle} <small>Module</small>
				<a href="${contextRoot}/${moduleTitle?lower_case}/add">
					<span class="glyphicon-class">add &#10010;</span>
				</a>
			</h1>
	</div>

	<div class="nav well">
		<form action="<@spring.url '/${moduleTitle?lower_case}/loadmore' />" class="navbar-form" role="search" method="POST">
			<input type="hidden" id="count" name="count" value="${count!''}"/>
			<input type="hidden" id="index" name="index" value="0"/>
			<input type="hidden" id="filter" name="filter" value="${filterVal[0].value}"/>

			<div class="dropdown">
				<label>Search by:</label>
				<select class="form-control filters selectpicker" >
					<#list filterVal as item>
						<option value="${item.value}">${item.filterText}</option>
					</#list>
				</select>
				<div class="form-group">
				  <input type="text" id="content" name="content" class="form-control" placeholder="Search" value="">
				</div>
				<a type="button" class="btn btn-primary btn-search">submit</a>
			</div>
			
		</form>
	</div>
</#macro>

<#macro backHeader action="" module="" extra="">
	<div class="page-header">
		<#if extra != "">
			<h1>${extra} <small>${action}</small>
				<a href="<@spring.url '/${module?lower_case}/' />">
							<span>&larr; back</span>
				</a>
			</h1>
		<#else>
			<h1>${module} <small>${action}</small>
				<a href="<@spring.url '/${module?lower_case}/' />">
							<span>&larr; back</span>
				</a>
			</h1>
		</#if>
	</div>
</#macro>

<#macro moduleHomeLayout moduleName list macroItem count>
<div class="main-wrapper cf">
	<@navFilter moduleName count />
	<div class="content cf">
		<#if list?size gt 0>
			<#assign curr=0/>
			<#list getList(list) as exam>
			    <#if curr < count>
			        <@macroItem exam />
			    </#if>
			    <#-- Load More -->
			    <#if curr == count-1>
			        <#if (getList(list)?size > count)>
			            <div class="clear load-more">
			                <form action="<@spring.url '/${moduleName?lower_case}/loadmore' />" method="POST">
			                    <input type="hidden" name="content" value="">
			                    <input type="hidden" name="index" value="${(count+1)?c}">
			                    <input type="hidden" name="count" value="${count}">
			                    <input type="hidden" name="filter" value="">
			                </form>
			                <a href="" class="btn-load"  data-wt="true">load More &#10010;</a>
			                
			            </div> 
			        </#if> 
			    </#if>
			    <#assign curr= curr + 1/>
			</#list>
		<#else>
			<div class="alert alert-warning">
			  <strong> Sorry</strong>, no ${moduleName}?lower_case at this time.
			</div>
		</#if>
	</div>
</div>
</#macro>